home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / USBTabletModule / USBTabletModuleConfigParse.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-25  |  2.0 KB  |  61 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        USBTabletModuleConfigParse.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.  
  11. */
  12.  
  13. #include <Types.h>
  14. #include <Devices.h>
  15. #include <processes.h>
  16. #include <DriverServices.h>
  17. #include <USB.h>
  18.  
  19.  
  20. #include "USBTabletModule.h"
  21.  
  22. OSErr FindHIDInterfaceByNumber(LogicalAddress pConfigDesc, UInt32 ReqInterface, USBInterfaceDescriptorPtr * hInterfaceDesc)
  23. {
  24. UInt32 totalLength;
  25. void * pEndOfDescriptors;
  26. USBInterfaceDescriptorPtr     pMyIntDesc;
  27. USBDescriptorHeaderPtr        pCurrentDesc;
  28. unsigned long                anAddress, anOffset;
  29.  
  30.     totalLength = USBToHostWord(((USBConfigurationDescriptorPtr)pConfigDesc)->totalLength);
  31.     pEndOfDescriptors = (Ptr)pConfigDesc + totalLength;                    // get the total length and add it to the start of the config space
  32.     pCurrentDesc = (USBDescriptorHeaderPtr)pConfigDesc;                    // point the currentdesc to the start of the config space
  33.     
  34.     while (pCurrentDesc < pEndOfDescriptors)                            // as long as we haven't exhausted all the descriptors
  35.     {
  36.         if (pCurrentDesc->descriptorType == kUSBInterfaceDesc)            // look at the current descriptor
  37.         {
  38.             pMyIntDesc = (USBInterfaceDescriptorPtr)pCurrentDesc;        // if it's an interface descriptor
  39.             if ((pMyIntDesc->interfaceClass == kUSBHIDInterfaceClass) &&
  40.                 (pMyIntDesc->interfaceNumber == ReqInterface))            // and if it's the interface we want...
  41.             {
  42.                 *hInterfaceDesc = pMyIntDesc;                            // if it is, then return with hInterfaceDesc set to the
  43.                 return noErr;                                            // current descriptor pointer
  44.             }
  45.         }
  46.         // (Ptr)pCurrentDesc += pCurrentDesc->length;                    // Nope, that either wasn't an interface descriptor
  47.         anAddress = (unsigned long) pCurrentDesc;                        // Nope, that either wasn't an interface descriptor
  48.         anOffset  = (unsigned long) pCurrentDesc->length;
  49.         anAddress += anOffset;
  50.         pCurrentDesc = (USBDescriptorHeaderPtr) anAddress;
  51.         if (pCurrentDesc->length == 0)
  52.             break;
  53.     }                                                                    // or it was, but not the droid we're looking for.
  54.     *hInterfaceDesc = NULL;
  55.     return kUSBInternalErr;
  56. }
  57.  
  58.  
  59.  
  60.  
  61.